﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class D04_Random1 : MonoBehaviour
{
    private void Update1()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            //Range方法取不到右边的值,左闭右开
            print(Random.Range(0f, 2f));
        }
    }
    /// <summary>
    /// 生成方块,位置随机,大小随机,颜色随机,旋转随机
    /// </summary>
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            //位置随机
            Vector3 Pos = Vector3.zero;
            Pos.x = Random.Range(0f, 10f);
            Pos.z = Random.Range(0f, 10f);
            cube.transform.position = Pos;

            //大小随机
            cube.transform.localScale = Vector3.one * Random.Range(0.5f, 1.5f);

            //颜色随机
            cube.GetComponent<Renderer>().material.color = Random.ColorHSV();

            //随机朝向
            cube.transform.rotation = Quaternion.Euler(0, Random.Range(0f, 360f), 0);     // Random.rotation;
        }
    }
}